﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using QuangNgai.nhaplieu.hosotailieu;
using QuangNgai.LTQNDataSetTableAdapters;
using DevExpress.XtraNavBar;
using QuangNgai.nhaplieu.vanban;
using QuangNgai.nhaplieu.tudien;
using QuangNgai.nhaplieu;
using System.Linq;
using DevExpress.XtraEditors;
using QuangNgai.nhaplieu.timkiemthongke;

namespace QuangNgai
{
    public partial class _frmMain : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        private int right = 12;
        private int verSpace = 12;

        public _frmMain()
        {
            InitializeComponent();
            ribbon.Minimized = true;
            //loadBienMucTaiLieu();
        }

        private void loadBienMucTaiLieu()
        {
            try
            {
                HsbooksTableAdapter hsAdap = new HsbooksTableAdapter();
                var hsData = hsAdap.GetData();
                for (int i = 0; i < hsData.Count; i++)
                {
                    QuangNgai.LTQNDataSet.HsbooksRow row = (LTQNDataSet.HsbooksRow)hsData.Rows[i];
                    string hsName = row.Bookname.Length == 0 ? "" : row.Bookname;
                    NavBarItem item = new DevExpress.XtraNavBar.NavBarItem(hsName);
                    item.SmallImageIndex = 7;
                    item.Name = row.Hsbooks_Id + "";
                    navGrpBienMucTaiLieu.ItemLinks.Add(item);
                    item.LinkClicked += new NavBarLinkEventHandler(navBarItem_Clicked);
                }
            }
            catch (StrongTypingException)
            {
            }
            catch (Exception)
            {
                throw;
            }

        }

        private void btnLoaiTaiLieu_ItemClick(object sender, ItemClickEventArgs e)
        {
            _formUtil.AddMdiChild(this, new frmLoaiTaiLieu());
        }

        private void btnTruongTinTaiLieu_ItemClick(object sender, ItemClickEventArgs e)
        {
            _formUtil.AddMdiChild(this, new frmTruongTinTaiLieu());
        }

        private void niLoaiTaiLieu_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _formUtil.AddMdiChild(this, new frmLoaiTaiLieu());
        }

        private void niTTTL_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _formUtil.AddMdiChild(this, new frmTruongTinTaiLieu());
        }

        private void niKhungHoSo_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _formUtil.AddMdiChild(this, new frmKhungNhapHoSo());
        }

        private void navBarItem_Clicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            //var item = sender as NavBarItem;
            //var taiLieuID = Convert.ToInt32(item.Name);
            //LTQNLinQDataContext db = new LTQNLinQDataContext();
            frmNhapHoSo frmNhap = new frmNhapHoSo();

            //Console.WriteLine(item.Name);
            //var dsTruongTin = from t in db.Hsfieldsattributes
            //                  where t.Hsbooks_Id == taiLieuID
            //                  select t;
            //verSpace = 12;
            //foreach (var tt in dsTruongTin)
            //{
            //    AddControl(frmNhap, HsFieldType.CHECKBOX, tt.Hsfield.Fullfieldname, tt.Hsfield.Fieldname);
            //    Console.WriteLine(tt.Hsfield.Fullfieldname);
            //}
            _formUtil.AddMdiChild(this, frmNhap);

        }

        private void _frmMain_Load(object sender, EventArgs e)
        {
            
        }


        private void niTTVB_LinkClicked(object sender, NavBarLinkEventArgs e)
        {
            _formUtil.AddMdiChild(this, new frmTruongTinVanBan());
        }

        private void niVanBan_LinkClicked(object sender, NavBarLinkEventArgs e)
        {
            _formUtil.AddMdiChild(this, new frmVanBan());
        }

        private void niKhungVB_LinkClicked(object sender, NavBarLinkEventArgs e)
        {
            _formUtil.AddMdiChild(this, new frmKhungNhapVanBan());
        }

        private void niDanhMucTD_LinkClicked(object sender, NavBarLinkEventArgs e)
        {
            _formUtil.AddMdiChild(this, new frmDanhMuc());
        }

        private void niTuDien_LinkClicked(object sender, NavBarLinkEventArgs e)
        {
            _formUtil.AddMdiChild(this, new frmTuDien());
        }

        private void niNhapHoSo_LinkClicked(object sender, NavBarLinkEventArgs e)
        {
            _formUtil.AddMdiChild(this,new frmNhapHoSo());
        }

        private void btnNhapHoSo_ItemClick(object sender, ItemClickEventArgs e)
        {
            niNhapHoSo_LinkClicked(null, null);
        }

        private void btnKhungHoSo_ItemClick(object sender, ItemClickEventArgs e)
        {
            niKhungHoSo_LinkClicked(null, null);
        }

        private void btnVanBan_ItemClick(object sender, ItemClickEventArgs e)
        {
            niVanBan_LinkClicked(null, null);
        }

        private void btnTruongTinVanBan_ItemClick(object sender, ItemClickEventArgs e)
        {
            niTTVB_LinkClicked(null, null);
        }

        private void btnKhungNhapVanBan_ItemClick(object sender, ItemClickEventArgs e)
        {
            niKhungVB_LinkClicked(null, null);
        }

        private void btnTuDien_ItemClick(object sender, ItemClickEventArgs e)
        {
            niTuDien_LinkClicked(null, null);
        }

        private void _frmMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            Environment.Exit(0);
        }

        private void niTimHS_LinkClicked(object sender, NavBarLinkEventArgs e)
        {
            _formUtil.AddMdiChild(this, new TimHSVB());
        }







    }
}